#include "buyinform.h"
#include "ui_buyinform.h"
#include "goodspurchasingwindow.h"
#include<QDebug>
buyinForm::buyinForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::buyinForm)
{
    ui->setupUi(this);
}

buyinForm::buyinForm(const QString &picPath, const QString &num, const QString &name, const double salePrice,
                     const int repetroy, const double buyinPrice, QWidget *parent):
    QWidget(parent),
    ui(new Ui::buyinForm)
{
    ui->setupUi(this);
    itemGoods=new goods(num,name,buyinPrice,salePrice,repetroy,0);
    ui->goodsPicLabel->setPixmap(QPixmap(picPath));
    ui->goodsLabel->setText(num);
    ui->goodsNaneLabel->setText(name);
    ui->goodsPricelabel->setNum(salePrice);
    ui->repertoryLabel->setNum(repetroy);
    ui->buyinPricelabel->setNum(buyinPrice);

    goodsPurchasingWindow* p1=dynamic_cast<goodsPurchasingWindow*>(parent);
    connect(this,&buyinForm::ValueChanged,p1,&goodsPurchasingWindow::getValue);
}

buyinForm::~buyinForm()
{
    delete ui;
}

goods* buyinForm::getItemGoods()
{
    return itemGoods;
}

void buyinForm::sendGoods()
{
    emit ValueChanged(itemGoods);
}

void buyinForm::on_pushButton_2_clicked()
{
    ui->amountEdit->setText(QString::number(ui->amountEdit->text().toInt()+1,10));
//   itemGoods->setBuyinNum(ui->amountEdit->text().toInt());
//   itemGoods->setRepertory(itemGoods->getRepertory()+1);

}

void buyinForm::on_pushButton_clicked()
{
     ui->amountEdit->setText(QString::number(ui->amountEdit->text().toInt()-1,10));
//     itemGoods->setBuyinNum(ui->amountEdit->text().toInt());
//     itemGoods->setRepertory(itemGoods->getRepertory()-1);
}

void buyinForm::on_amountEdit_textChanged(const QString &arg1)
{
    itemGoods->setBuyinNum(arg1.toInt());
    itemGoods->setRepertory(itemGoods->getRepertory()+arg1.toInt());

}
